<?php $this->load->view('cms/article/message'); ?>
<?php $paginator = $this->load->view('cms/article/paginator', array('related' => true), true); echo $paginator; ?>
<input type="hidden" name="current_page" id="current_page" value="<?php echo $current_page; ?>" />
<div class="block" id="lst_article">
    <table class="gridview" width="100%" cellpadding="0" cellspacing="0" border="0">
        <thead>
        <tr>
            <td><b>ID</b></td>
            <td><b>Chọn</b></td>
            <td colspan="3"><b>Tiêu đề</b></td>
            <td colspan="5"><b>Tiêu chí khác</b></td>
        </tr>
        </thead>
        <tbody>
        <tr class="filters">
            <td colspan="2">
                <input placeholder="ID" type="text" class="bind_enter_evt small_filter" name="filters[ca.id][value]" title="Tìm kiếm theo id bài viết" value="<?php echo $filters['ca.id']['value']; ?>" onchange="return admin_cms_article.act_filter_related('filter_related_list', '', <?php echo $type; ?>)" />
                <input type="hidden" value="equal" name="filters[ca.id][type]" />
            </td>
            <td colspan="2">
                <input placeholder="Từ khóa" type="text" class="bind_enter_evt wide_filter" name="filters[title][value]" title="Tìm kiếm theo tiêu đề bài viết" value="<?php echo $filters['title']['value']; ?>" onchange="return admin_cms_article.act_filter_related('filter_related_list', '', <?php echo $type; ?>)" />
                <input type="hidden" value="text" name="filters[title][type]" />
            </td>
            <td>
                <select style="width: 120px" onchange="return admin_cms_article.act_filter_related('filter_related_list', '', <?php echo $type; ?>)" placeholder="Tất cả" name="filters[user_id][value]">
                    <option value="-1">-- Tất cả --</option>
                    <?php foreach ($users as $user) :?>
                    <option <?php if (isset($filters['user_id']['value']) && $filters['user_id']['value'] == get_field($user, 'id')) :?>selected="selected"<?php endif; ?> value="<?php echo get_field($user, 'id'); ?>">
                        <?php echo get_field($user, 'username'); ?>
                    </option>
                    <?php endforeach; ?>
                </select>
                <input type="hidden" value="equal" name="filters[user_id][type]" />
                <input type="hidden" value="-1" name="filters[user_id][exclude]" />
            </td>
            <td>
                <select style="width: 130px" onchange="return admin_cms_article.act_filter_related('filter_related_list', '', <?php echo $type; ?>)" placeholder="Tất cả" name="filters[ca.category_ids][value]">
                    <option value="-1">-- Tất cả --</option>
                    <?php foreach ($categories as $cat) :?>
                    <?php if (intval($cat->parent_id) > 0) :?>└--<?php endif; ?>
                    <option <?php if (isset($filters['ca.category_ids']['value']) && intval($filters['ca.category_ids']['value']) == intval($cat->id)) :?>selected="selected"<?php endif; ?> value="<?php echo get_field($cat, 'id'); ?>"><?php echo get_field($cat, 'name'); ?></option>
                    <?php endforeach; ?>
                </select>
                <input type="hidden" value="text" name="filters[ca.category_ids][type]" />
                <input type="hidden" value="-1" name="filters[ca.category_ids][exclude]" />
            </td>
            <td width="150px" colspan="2">
                <button class="gray_btn" type="button" onclick="return admin_cms_article.act_filter_related('filter_related_list', '', <?php echo $type; ?>)">
                    <span>Lọc</span>
                </button>
                <button class="gray_btn" type="button" onclick="return admin_cms_article.reset_filter_related('filter_related_list', '', <?php echo $type; ?>)">
                    <span>Xóa lọc</span>
                </button>
            </td>
        </tr>
        <?php if (count($collection) != 0) : ?>
            <?php foreach ($collection as $article) : ?>
            <tr>
                <input type="hidden" value="" class="edit_url"/>
                <td width="30px" valign="top" class="related_article_id">
                    <?php echo $article->id; ?>
                </td>
                <td width="30px" valign="top">
                    <?php if($type == 1) : ?>
                    <strong><a id="btn_related_<?php echo $article->id; ?>" onclick="return admin_cms_article.add_related_disease(<?php echo $article->id; ?>, '<?php echo htmlspecialchars($article->title); ?>', '<?php echo render_site_url($article->alias . '-' . $article->id); ?>', 'article_related')" title="Chọn bài viết" class="icon icon_add_blue" href="#"></a></strong>
                    <?php else : ?>
                    <strong><a id="btn_related_<?php echo $article->id; ?>" onclick="return admin_cms_article.add_related(<?php echo $article->id; ?>, '<?php echo htmlspecialchars($article->title); ?>', '<?php echo render_site_url($article->alias . '-' . $article->id); ?>', 'article_related')" title="Chọn bài viết" class="icon icon_add_blue" href="#"></a></strong>
                    <?php endif; ?>

                </td>
                <td valign="top" width="100%" colspan="7">
                    <div class="bl">
                        <div class="frame" style="width: 100px; height: 80px; overflow: hidden;">
                            <img class="related_article_image" width="100px" src="<?php echo render_src($article->image); ?>" />
                        </div>
                    </div>
                    <div class="bl ml_10" style="min-width: 500px">
                        <p><strong><a target="_blank" class="related_article_title" href="<?php echo site_url('admin/cms/article/edit/id/' . $article->id . '/return/' . $return_url, true); ?>"><?php echo get_field($article, 'title'); ?></a></strong></p>
                        <p class="small_datetime"><span class="icon icon_author"></span> Gửi bởi: <strong><?php echo get_field($article, 'author'); ?></strong> - Ngày gửi: <strong><?php echo render_date(get_field($article, 'created_at')); ?></strong> - Xuất bản: <strong><?php echo render_date(get_field($article, 'publish_day')); ?></strong></p>
                        <p class="small_datetime" style="width: 600px">
                            <?php echo $article->description; ?>
                        </p>
                        <div class="clearfix auto_height mt_10">
                            <p class="clearfix">
                                <strong><a target="_blank" title="Chỉnh sửa" class="icon icon_edit" href="<?php echo site_url('admin/cms/article/edit/id/' . $article->id . '/return/deleted', true); ?>"></a></strong>
                                <strong><a title="Xem trước bài viết" onclick="return admin_cms_article.preview_article(<?php echo $article->id; ?>)" class="icon icon_preview" href="<?php echo site_url('admin/cms/article/preview_article/id/' . $article->id . '/return/deleted', true); ?>"></a></strong>
                            </p>
                            <div class="bl">
                                <div class="bl">
                                    <input id="chk_<?php echo $article->id; ?>_hot_article" onclick="return admin_cms_article.update_hot_article(this)" type="checkbox" value="<?php echo $article->id; ?>" <?php if (get_field($article, 'hot_article') == 1) :?>checked="checked"<?php endif; ?>/>
                                </div>
                                <div class="bl">
                                    <label for="chk_<?php echo $article->id; ?>_hot_article" style="line-height: 20px; margin-left: 2px">Tiêu điểm</label>
                                </div>
                            </div>
                            <div class="bl">
                                <div class="bl">
                                    <input id="chk_<?php echo $article->id; ?>_top_home" onclick="return admin_cms_article.update_top_home(this)" type="checkbox" value="<?php echo $article->id; ?>" <?php if (get_field($article, 'top_home') == 1) :?>checked="checked"<?php endif; ?>/>
                                </div>
                                <div class="bl">
                                    <label for="chk_<?php echo $article->id; ?>_top_home" style="line-height: 20px; margin-left: 2px">Nổi bật trang chủ</label>
                                </div>
                            </div>
                            <div class="bl">
                                <div class="bl">
                                    <input id="chk_<?php echo $article->id; ?>_top_category" onclick="return admin_cms_article.update_top_category(this)" type="checkbox" value="<?php echo $article->id; ?>" <?php if (get_field($article, 'top_category') == 1) :?>checked="checked"<?php endif; ?>/>
                                </div>
                                <div class="bl">
                                    <label for="chk_<?php echo $article->id; ?>_top_category" style="line-height: 20px; margin-left: 2px">Nổi bật mục</label>
                                </div>
                            </div>
                            <div class="clearfix"></div>
                        </div>
                    </div>
                </td>
            </tr>
                <?php endforeach; ?>
            <?php else : ?>
        <tr>
            <td colspan="9" style="padding: 10px">
                <p align="center">Không tìm thấy bài viết nào đã xuất bản</p>
            </td>
        </tr>
            <?php endif; ?>
        </tbody>
        <tfoot>
        </tfoot>
    </table>
</div>
<?php echo $paginator; ?>
<script type="text/javascript">
    var group_cat_relate = <?php echo $category_relate; ?>;
    $(".bind_enter_evt").each(function() {
        $(this).bind('keypress', function(e) {
            var code = (e.keyCode ? e.keyCode : e.which);
            if (code == 13) {
                $(this).trigger("change");
            } else {
                return true;
            }
            return false;
        });
    });
</script>